package com.gemantic.user.service.impl;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gemantic.user.dao.UserMapper;
import com.gemantic.user.model.User;
import com.gemantic.user.service.UserService;
import com.google.common.collect.Lists;

/**
*
*
* created by wangshoufa
* 2018年5月23日 下午4:08:51
*
*/

@Service
public class UserServiceImpl implements UserService {
	
	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public List<User> getUser() {
		List<User> ls = Lists.newArrayList();
		try {
			ls = userMapper.getUser();
		} catch (Exception e) {
			return ls;
		}
		return ls;
	}

	@Transactional
	@Override
	public int update(Long id, String name) throws Exception {
		userMapper.insertUser(name+"ssssssss");
		userMapper.updateUserById(id,name);
		return 1;
	}

	@Override
	public List<User> getInfo() {
		List<User> l = Lists.newArrayList();
		User u = new User();
		u.setId(1L);
		u.setName("ssssssss");
		l.add(u);
		return l;
	}

	@Override
	public User getUserInfoById(Long id) {
		User user = userMapper.getUserInfoById(id);
		return user;
	}
	
	
	@Transactional
	@Override
	public boolean updateUserByid(Long id, String name) throws Exception {
		boolean resu = false;
		User user = userMapper.getUserInfoById(id);
		logger.info("user: " + user);
		if (user != null) {
			int dd = userMapper.updateUserById(user.getId(), name);
			logger.info("deal resu: " + resu);
		}
		return resu;
	}
	

}
